<?php


namespace app\admin\controller;

use app\admin\model\Admin as AdminModel;
use think\Controller;
use think\Db;
class Login extends Controller
{
public function login(){
    return $this->fetch();
}

public function dologin($username,$password){
    $user=Db::name('admin')->where('username',$username)->find();
    if(empty($user)){
        $this->error('用户不存在');
    }
    if($user['userpwd']==$password){
       session('username',$username);
        $this->success('登陆成功','index/main');
    }else{
        $this->error('用户名或密码不正确');
    }
}
public function logout(){
    session(null);
    $this->success('退出成功','login/login');
}
    public function register(){
        return $this->fetch();
    }

    public function doreg(){
    $data=$this->request->param();
    $result=$this->validate($data,[
        'username'=>'require|min:6',
        'userpwd'=>'require',
'email'=>'require'
//        'code|验证码'=>'require|captcha'
    ]);
    if(true!==$result){
        dump($result);
    }
    else{
        $data=$this->request->param();
        $model=new AdminModel();
        $res=$model->add($data);
        if($res){
            $this->success('注册成功','login/login');
        }else{
            $this->error('注册失败');
        }
    }
    }

}